<template>
  <div id="addActives">
    <el-row type="flex" justiify="center">
      <el-col :span="12" :offset="0">
        <h1 class="con-right-title">
          新增邀请活动
        </h1>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="22" :offset="1">
        <el-form
          ref="activityInfo"
          label-width="150px"
          :model="activityInfo"
          :rules="activityInfoRules"
        >
          <el-form-item label="活动名称" prop="name">
            <el-input
              class="activity-input"
              type="text"
              size="small"
              show-word-limit
              :clearable="true"
              :maxLength="maxLength"
              v-model.trim="activityInfo.name"
            ></el-input>
          </el-form-item>
          <el-form-item label="活动起始时间" prop="activityTime">
            <el-date-picker
              v-model="activityInfo.activityTime"
              type="datetimerange"
              size="small"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              format="yyyy-MM-dd HH:mm:ss"
              value-format="yyyy-MM-dd HH:mm:ss"
              @change="changeActivityTime"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="预热时间">
            <el-radio-group v-model="activityInfo.warmUpConfig.open">
              <el-radio :label="true">开启</el-radio>
              <el-radio :label="false">关闭</el-radio>
            </el-radio-group>
            <el-form-item
              :rules="{
                required: activityInfo.warmUpConfig.open ? true : false,
                message: '预热时间',
                trigger: ['change', 'blur']
              }"
              v-if="activityInfo.warmUpConfig.open"
              prop="warmUpConfig.preheatTime"
            >
              <el-date-picker
                v-model="activityInfo.warmUpConfig.preheatTime"
                type="datetimerange"
                size="small"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                format="yyyy-MM-dd HH-mm"
                value-format="yyyy-MM-dd HH:mm:ss"
                @change="changePreheatTime"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item
              :rules="{
                required: activityInfo.warmUpConfig.open ? true : false,
                message: '封面海报',
                trigger: 'change'
              }"
              v-if="activityInfo.warmUpConfig.open"
              prop="warmUpConfig.cover"
            >
              <div class="form-option">
                <uploadSingImg
                  :imgUrl="activityInfo.warmUpConfig.cover"
                  accept=".jpg,.jpeg,.png,.gif"
                  :maxSize="5"
                  @getImgUrl="getImgUrl"
                >
                  <template v-slot:imgInfo>
                    <span
                      >（请上传图片尺寸1242*2688，支持gif，尺寸最大5M）</span
                    >
                  </template>
                </uploadSingImg>
              </div>
            </el-form-item>
          </el-form-item>

          <el-form-item label="领奖时间">
            <el-radio-group v-model="activityInfo.receiveAwardConfig.open">
              <el-radio :label="true">开启</el-radio>
              <el-radio :label="false">关闭</el-radio>
            </el-radio-group>
            <el-form-item
              v-if="activityInfo.receiveAwardConfig.open"
              prop="receiveAwardConfig.receiveTime"
              :rules="{
                required:
                  activityInfo.receiveAwardConfig.open === true ? true : false,
                message: '领奖时间',
                trigger: 'change'
              }"
            >
              <el-date-picker
                v-model="activityInfo.receiveAwardConfig.receiveTime"
                type="datetimerange"
                size="small"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss"
                @change="changeReceiveTime"
              >
              </el-date-picker>
            </el-form-item>
          </el-form-item>
          <el-form-item label="选择学院" prop="collegeId">
            <el-select
              v-model="activityInfo.collegeId"
              placeholder="请选择学院"
              size="small"
            >
              <el-option
                v-for="item in collegesList"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="跑马灯">
            <el-radio-group v-model="activityInfo.marqueeOpen">
              <el-radio :label="true">开启</el-radio>
              <el-radio :label="false">关闭</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>
        <!-- 邀请活动表单 -->
        <el-form
          label-width="150px"
          ref="inviteActivityConfig"
          label-position="right"
          :model="inviteActivityConfig"
          :rules="inviteActivityConfigRules"
        >
          <el-form-item label="活动海报" prop="poster">
            <uploadSingImg
              :imgUrl="inviteActivityConfig.poster"
              accept=".jpg,.jpeg,.png,.gif"
              :maxSize="5"
              @getImgUrl="getActivePoster"
            >
              <template v-slot:imgInfo>
                <span>（请上传图片尺寸1242*2688，支持gif，尺寸最大5M）</span>
              </template>
            </uploadSingImg>
          </el-form-item>
          <el-form-item label="活动规则" prop="ruleDescribe">
            <el-radio-group
              @change="clearFileds"
              v-model="inviteActivityConfig.ruleDescribeOpen"
            >
              <el-radio :label="true">开启</el-radio>
              <el-radio :label="false">关闭</el-radio>
            </el-radio-group>
            <div
              v-if="inviteActivityConfig.ruleDescribeOpen == true"
              style="width:100%"
            >
              <quill-editor
                ref="text"
                style="height:110px"
                v-model="inviteActivityConfig.ruleDescribe"
                class="myQuillEditor"
                :options="editorOption"
                @change="onEditorChange($event)"
                @blur="onEditorBlur($event)"
              ></quill-editor>
            </div>
            <div
              class="limit"
              v-if="inviteActivityConfig.ruleDescribeOpen == true"
            >
              <span>{{ nowLength }}</span> / {{ maxLen }}
            </div>
          </el-form-item>
        </el-form>
        <el-form label-width="150px">
          <el-form-item label="邀请模式">
            <el-radio-group
              v-model="inviteActivityConfig.inviteUserAwards.awardModel"
            >
              <el-radio
                v-for="(item, index) in awardModelList"
                :key="index"
                :label="item.dictValue"
                >{{ item.dictLabel }}</el-radio
              >
            </el-radio-group>
          </el-form-item>
        </el-form>

        <el-form
          ref="generalRef"
          v-if="
            inviteActivityConfig.inviteUserAwards.awardModel ==
              'GENERAL_REWARD_MODEL'
          "
          label-width="150px"
          :model="generalRewardObj"
        >
          <el-form-item label="邀请人奖励(选填)">
            <div
              v-for="(item, index) in generalRewardObj.generalRewardAwards"
              :key="index"
              class="award-option"
            >
              <el-form-item
                :prop="`generalRewardAwards[${index}].virtualPrizeTypes`"
                :rules="[
                  {
                    validator: (rules, value, callback) => {
                      validGeneral(rules, value, callback)
                    }
                  }
                ]"
              >
                <el-select
                  v-model="item.virtualPrizeTypes"
                  size="small"
                  @change="
                    (val) => {
                      changeInviteUserAward(val, index, item)
                    }
                  "
                >
                  <el-option
                    v-for="virtualPrize in virtualPrizeTypeList"
                    :key="virtualPrize.dictValue"
                    :label="virtualPrize.dictLabel"
                    :value="virtualPrize.dictValue"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <!-- 积分数量 -->
              <el-form-item
                ref="generalNum"
                :prop="`generalRewardAwards[${index}].num`"
                :rules="{
                  required: item.virtualPrizeTypes == 'INTEGRAL',
                  message: '请输入积分数量',
                  trigger: ['change', 'blur']
                }"
              >
                <el-input-number
                  v-if="item.virtualPrizeTypes === 'INTEGRAL'"
                  v-model="item.num"
                  class="prize-option"
                  controls-position="right"
                  size="small"
                  :precision="0"
                  :min="1"
                  :max="awardLength"
                ></el-input-number>
              </el-form-item>
              <!-- 优惠券 -->
              <el-form-item
                ref="generalCop"
                :prop="`generalRewardAwards[${index}].couponId`"
                :rules="{
                  required: item.virtualPrizeTypes === 'COUPON',
                  message: '选择优惠券',
                  trigger: 'change'
                }"
              >
                <el-button
                  v-if="item.virtualPrizeTypes === 'COUPON' && !item.prizeName"
                  class="coupon-add_btn"
                  size="small"
                  type="primary"
                  @click="addCoupons(index, '', 'general')"
                  >添加优惠券</el-button
                >
                <el-button
                  size="small"
                  class="btnClass"
                  v-if="item.virtualPrizeTypes == 'COUPON' && item.prizeName"
                  >{{ item.prizeName }}</el-button
                >
                <el-button
                  size="small"
                  style="height: 32px; margin-left: 10px"
                  type="primary"
                  @click="addCoupons(index, '', 'general')"
                  v-if="item.prizeName && item.virtualPrizeTypes == 'COUPON'"
                  >重新选择</el-button
                >
              </el-form-item>
              <!-- 鲜花 -->
              <el-form-item
                ref="generalFlower"
                :prop="`generalRewardAwards[${index}].num`"
                :rules="{
                  required: item.virtualPrizeTypes === 'FLOWER',
                  message: '请选择鲜花数量',
                  trigger: 'blur'
                }"
              >
                <el-input-number
                  v-if="item.virtualPrizeTypes === 'FLOWER'"
                  v-model="item.num"
                  class="prize-option"
                  controls-position="right"
                  size="small"
                  :precision="0"
                  :min="1"
                  :max="awardLength"
                ></el-input-number>
              </el-form-item>
              <!-- 实物奖品 -->
              <el-form-item
                ref="generalPhy"
                :prop="`generalRewardAwards[${index}].prizeName`"
                :rules="{
                  required: item.virtualPrizeTypes === 'PHYSICALS_PRIZE',
                  message: '填写实物名称',
                  trigger: 'blur'
                }"
              >
                <el-input
                  style="height:35px;"
                  v-if="item.virtualPrizeTypes === 'PHYSICALS_PRIZE'"
                  v-model="item.prizeName"
                  class="prize-input"
                  clearable
                  :maxlength="maxLength"
                >
                </el-input>
              </el-form-item>
              <el-button
                style="height:32px;margin-left:10px"
                size="small"
                type="danger"
                icon="el-icon-delete"
                @click="deleteInviteUserAwards(index)"
                >删除</el-button
              >
              <el-button
                style="height:32px;margin-left:10px"
                size="small"
                v-if="index == generalRewardObj.generalRewardAwards.length - 1"
                icon="el-icon-plus"
                type="primary"
                @click="addInviteUserAwards(index)"
                >添加</el-button
              >
            </div>
          </el-form-item>
        </el-form>
        <!-- 阶梯奖励 -->
        <el-form
          :model="stateObj"
          label-width="150px"
          ref="ladderForm"
          v-if="
            inviteActivityConfig.inviteUserAwards.awardModel ==
              'LADDER_REWARD_MODEL'
          "
        >
          <el-form-item label="邀请人奖励(选填)">
            <div
              v-for="(item, index) of stateObj.stage"
              :key="index"
              class="ladder"
            >
              <span style="font-size: 20px; font-weight: bold"
                >第{{ index + 1 }}阶段</span
              >
              <div
                style="margin: 20px 0 0 100px;display:flex"
                v-for="(inner, ind) of stateObj.stage[index]"
                :key="ind"
              >
                <!-- 阶梯奖品类型 -->
                <el-form-item
                  :prop="`stage[${index}][${ind}].virtualPrizeTypes`"
                  :rules="[
                    {
                      validator: (rules, value, callback) => {
                        validLadder(rules, value, callback)
                      },
                      trigger: ['blur', 'change']
                    }
                  ]"
                >
                  <el-select
                    size="small"
                    v-model="inner.virtualPrizeTypes"
                    placeholder="请选择奖品类型"
                    @change="
                      (val) => {
                        checkLabelState(val, ind, index)
                      }
                    "
                  >
                    <el-option
                      v-for="item in virtualPrizeTypeList"
                      :key="item.dictValue"
                      :label="item.dictLabel"
                      :value="item.dictValue"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
                <!-- 积分数量 -->
                <el-form-item
                  ref="ladderNum"
                  :prop="`stage[${index}][${ind}].num`"
                  :rules="[
                    {
                      required: inner.virtualPrizeTypes === 'INTEGRAL',
                      message: '请填写积分数量',
                      trigger: ['blur', 'change']
                    }
                  ]"
                >
                  <el-input-number
                    size="small"
                    :precision="0"
                    v-if="item[ind].virtualPrizeTypes == 'INTEGRAL'"
                    style="margin-left:10px"
                    v-model="item[ind].num"
                    controls-position="right"
                    :min="1"
                    :max="awardLength"
                  ></el-input-number>
                </el-form-item>
                <!-- 鲜花 -->
                <el-form-item
                  ref="ladderNum"
                  :prop="`stage[${index}][${ind}].num`"
                  :rules="[
                    {
                      required: inner.virtualPrizeTypes === 'FLOWER',
                      message: '请填写积分数量',
                      trigger: ['blur', 'change']
                    }
                  ]"
                >
                  <el-input-number
                    size="small"
                    :precision="0"
                    v-if="item[ind].virtualPrizeTypes == 'FLOWER'"
                    style="margin-left:10px"
                    v-model="item[ind].num"
                    controls-position="right"
                    :min="1"
                    :max="awardLength"
                  ></el-input-number>
                </el-form-item>
                <!-- 优惠券 -->
                <el-form-item
                  ref="ladderCop"
                  :prop="`stage[${index}][${ind}].couponId`"
                  :rules="[
                    {
                      required: inner.virtualPrizeTypes === 'COUPON',
                      message: '请选择优惠券',
                      trigger: ['blur', 'change']
                    }
                  ]"
                >
                  <el-button
                    class="coupon-add_btn m_left"
                    size="small"
                    @click="addCoupons(index, ind, 'ladder')"
                    v-if="
                      item[ind].virtualPrizeTypes == 'COUPON' &&
                        !item[ind].prizeName
                    "
                    type="primary"
                    >添加优惠券</el-button
                  >
                  <el-button
                    size="small"
                    v-if="
                      item[ind].virtualPrizeTypes == 'COUPON' &&
                        item[ind].prizeName
                    "
                    class="m_left btnClass coupon-add_btn"
                    >{{ item[ind].prizeName }}</el-button
                  >
                  <el-button
                    size="small"
                    @click="addCoupons(index, ind, 'ladder')"
                    v-if="
                      item[ind].virtualPrizeTypes == 'COUPON' &&
                        item[ind].prizeName
                    "
                    type="primary"
                    class="m_left"
                    style="height:32px"
                    >重新选择</el-button
                  >
                </el-form-item>
                <!-- 实物名称 -->
                <el-form-item
                  ref="ladderPhy"
                  :prop="`stage[${index}][${ind}].prizeName`"
                  :rules="[
                    {
                      required: inner.virtualPrizeTypes === 'PHYSICALS_PRIZE',
                      message: '请填写实物名称',
                      trigger: ['blur', 'change']
                    }
                  ]"
                >
                  <el-input
                    size="small"
                    v-model="item[ind].prizeName"
                    @blur="item[ind].prizeName = $event.target.value.trim()"
                    clearable
                    :maxlength="maxLength"
                    style="width: 200px; margin-left: 10px"
                    v-if="item[ind].virtualPrizeTypes == 'PHYSICALS_PRIZE'"
                  >
                  </el-input>
                </el-form-item>

                <el-button
                  @click="deleteInner(ind, index)"
                  type="danger"
                  icon="el-icon-delete"
                  style="
                      margin-left:10px;
                      width: 80px;
                      height:32px;
                    "
                  >删除</el-button
                >
                <el-button
                  v-if="ind == item.length - 1"
                  @click="addInner(ind, index)"
                  class="m_left coupon-add_btn"
                  type="primary"
                  icon="el-icon-plus"
                  style="
                      height: 32px;
                      width: 80px;
                    "
                  >添加</el-button
                >
              </div>
              <div style="margin:20px 0 0 100px">无奖励，可不填写该项</div>
              <div style="margin-left: 80px">
                <el-button
                  @click="deleteStage(index)"
                  class="m_left coupon-add_btn"
                  type="danger"
                  icon="el-icon-delete"
                  style="
                   height: 35px;
                    width: 150px;
                    color: white;
                    background: rgb(217, 0, 27);
                    border-radius: 10px;
                  "
                  >删除</el-button
                >
                <el-button
                  v-if="index == stateObj.stage.length - 1"
                  @click="addStage"
                  class="m_left coupon-add_btn"
                  type="primary"
                  icon="el-icon-plus"
                  style="
                    height: 35px;
                    width: 150px;
                    color: white;
                    background: rgb(22, 155, 213);
                    border-radius: 10px;
                  "
                  >添加</el-button
                >
              </div>
            </div>
          </el-form-item>
        </el-form>
        <!-- 用户行为奖励 -->
        <el-form
          class="behavior"
          ref="behaviorRef"
          label-width="150px"
          :model="behaviorRewardsObj"
        >
          <el-form-item label="用户行为奖励" class="behaviorInner">
            <div
              class="award-option"
              v-for="(item, index) in behaviorRewardsObj.behaviorRewards"
              :key="index"
            >
              <!-- 选择用户行为 -->
              <el-form-item
                :prop="`behaviorRewards[${index}].userBehavior`"
                :rules="[
                  {
                    required: behaviorAwardCheck,
                    message: '请选择用户行为',
                    trigger: ['blur', 'change']
                  }
                ]"
              >
                <el-select v-model="item.userBehavior" size="small">
                  <el-option
                    v-for="behavior in userBehaviorList"
                    :key="behavior.dictValue"
                    :label="behavior.dictLabel"
                    :value="behavior.dictValue"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <!-- 选择奖品 -->
              <el-form-item
                class="row_center near-top"
                :prop="`behaviorRewards[${index}].prize.virtualPrizeTypes`"
                :rules="[
                  {
                    required: behaviorAwardCheck,
                    message: '请选择奖品类型',
                    trigger: ['change', 'blur']
                  }
                ]"
              >
                <el-select
                  class="prize-option"
                  v-model="item.prize.virtualPrizeTypes"
                  size="small"
                  @change="
                    (val) => {
                      checkedUserBehavor(val, index)
                    }
                  "
                >
                  <el-option
                    v-for="virtualPrize in virtualPrizeTypeList"
                    :key="virtualPrize.dictValue"
                    :label="virtualPrize.dictLabel"
                    :value="virtualPrize.dictValue"
                    :disabled="virtualPrize.disabled"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <!-- 积分数量 -->
              <el-form-item
                class="form-near-top"
                ref="behaviorNum"
                v-if="item.prize.virtualPrizeTypes == 'INTEGRAL'"
                :prop="`behaviorRewards[${index}].prize.num`"
                :rules="{
                  required: item.prize.virtualPrizeTypes === 'INTEGRAL',
                  message: '积分数量',
                  trigger: 'blur'
                }"
              >
                <el-input-number
                  style="margin-left:10px"
                  size="small"
                  :precision="0"
                  class="m_left"
                  v-model="item.prize.num"
                  controls-position="right"
                  :min="1"
                  :max="awardLength"
                ></el-input-number>
              </el-form-item>
              <!-- 鲜花 -->
              <el-form-item
                class="form-near-top"
                ref="behaviorNum"
                v-if="item.prize.virtualPrizeTypes == 'FLOWER'"
                :prop="`behaviorRewards[${index}].prize.num`"
                :rules="{
                  required: item.prize.virtualPrizeTypes === 'FLOWER',
                  message: '请填写鲜花数量',
                  trigger: 'blur'
                }"
              >
                <el-input-number
                  style="margin-left:10px"
                  size="small"
                  :precision="0"
                  class="m_left"
                  v-model="item.prize.num"
                  controls-position="right"
                  :min="1"
                  :max="awardLength"
                ></el-input-number>
              </el-form-item>
              <!-- 优惠券 -->
              <el-form-item
                class="row_center form-near-top"
                ref="behaviorCounp"
                :prop="`behaviorRewards[${index}].prize.couponId`"
                :rules="{
                  required: item.prize.virtualPrizeTypes === 'COUPON',
                  message: '选择优惠券',
                  trigger: 'change'
                }"
              >
                <el-button
                  v-if="
                    item.prize.virtualPrizeTypes === 'COUPON' &&
                      !item.prize.prizeName
                  "
                  class="coupon-add_btn"
                  size="small"
                  type="primary"
                  @click="addCoupons(index, '', 'behavior')"
                  >添加优惠券</el-button
                >
                <el-button
                  size="small"
                  style="height: 32px; margin-left: 10px"
                  class="btnClass"
                  v-if="
                    item.prize.virtualPrizeTypes == 'COUPON' &&
                      item.prize.prizeName
                  "
                  >{{ item.prize.prizeName }}</el-button
                >
                <el-button
                  size="small"
                  style="height: 32px; margin-left: 10px"
                  type="primary"
                  @click="addCoupons(index, '', 'behavior')"
                  v-if="
                    item.prize.prizeName &&
                      item.prize.virtualPrizeTypes == 'COUPON'
                  "
                  >重新选择</el-button
                >
              </el-form-item>
              <!-- 实物奖品 -->
              <el-form-item
                class="row_center form-near-top"
                ref="behaviorPhy"
                :prop="`behaviorRewards[${index}].prize.prizeName`"
                :rules="{
                  required: item.prize.virtualPrizeTypes === 'PHYSICALS_PRIZE',
                  message: '填写实物名称',
                  trigger: 'blur'
                }"
              >
                <el-input
                  v-if="item.prize.virtualPrizeTypes === 'PHYSICALS_PRIZE'"
                  v-model.trim="item.prize.prizeName"
                  class="prize-input"
                  clearable
                  :maxlength="maxLength"
                >
                </el-input>
              </el-form-item>
              <el-form-item
                :inline-message="true"
                class="row_center behavior-item"
                :prop="`behaviorRewards[${index}].userBehavior`"
                :rules="[
                  {
                    validator: (rules, value, callback) => {
                      validBehavior(rules, value, callback)
                    }
                  }
                ]"
              >
                <el-button
                  style="height:32px;"
                  @click="deleteUserMove(index)"
                  class="form-btn"
                  type="danger"
                  icon="el-icon-delete"
                  size="small"
                  >删除</el-button
                >
              </el-form-item>

              <el-button
                v-if="index == behaviorRewardsObj.behaviorRewards.length - 1"
                @click="addUserMove()"
                class="form-btn form-near-top btn-height"
                type="primary"
                icon="el-icon-plus"
                size="small"
                >添加</el-button
              >
            </div>
          </el-form-item>
        </el-form>
        <!-- 被邀请人奖励 -->
        <el-form ref="beInvitees" :model="inviteesUserObj" label-width="150px">
          <el-form-item label="被邀请人奖励">
            <div
              v-for="(item, index) in inviteesUserObj.inviteesUserAwards"
              :key="index"
              class="award-option"
            >
              <el-form-item
                :prop="`inviteesUserAwards[${index}].virtualPrizeTypes`"
                :rules="[
                  {
                    required:
                      inviteesUserObj.inviteesUserAwards.length > 1
                        ? true
                        : false,
                    message: '请选择奖品类型',
                    trigger: 'blur'
                  },
                  {
                    validator: (rules, value, callback) => {
                      validBeInvite(rules, value, callback)
                    },
                    trigger: ['change', 'blur']
                  }
                ]"
              >
                <el-select
                  v-model="item.virtualPrizeTypes"
                  size="small"
                  @change="
                    (val) => {
                      checkedAward(val, index, item)
                    }
                  "
                >
                  <el-option
                    v-for="virtualPrize in virtualPrizeTypeList"
                    :key="virtualPrize.dictValue"
                    :label="virtualPrize.dictLabel"
                    :value="virtualPrize.dictValue"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <!-- 积分数量 -->
              <el-form-item
                ref="beinvitedNum"
                v-if="item.virtualPrizeTypes == 'INTEGRAL'"
                :prop="`inviteesUserAwards[${index}].num`"
                :rules="{
                  required: item.virtualPrizeTypes === 'INTEGRAL',
                  message: '积分数量',
                  trigger: 'blur'
                }"
              >
                <el-input-number
                  style="margin-left:10px"
                  size="small"
                  :precision="0"
                  class="m_left"
                  v-model="item.num"
                  controls-position="right"
                  :min="1"
                  :max="awardLength"
                ></el-input-number>
              </el-form-item>
              <!-- 鲜花 -->
              <el-form-item
                ref="beinvitedNum"
                v-if="item.virtualPrizeTypes == 'FLOWER'"
                :prop="`inviteesUserAwards[${index}].num`"
                :rules="{
                  required: item.virtualPrizeTypes === 'FLOWER',
                  message: '请填写鲜花数量',
                  trigger: 'blur'
                }"
              >
                <el-input-number
                  style="margin-left:10px"
                  size="small"
                  :precision="0"
                  class="m_left"
                  v-model="item.num"
                  controls-position="right"
                  :min="1"
                  :max="awardLength"
                ></el-input-number>
              </el-form-item>
              <!-- 优惠券 -->
              <el-form-item
                ref="beinvitedCoup"
                :prop="`inviteesUserAwards[${index}].couponId`"
                :rules="{
                  required: item.virtualPrizeTypes === 'COUPON',
                  message: '选择优惠券',
                  trigger: 'change'
                }"
              >
                <el-button
                  v-if="item.virtualPrizeTypes === 'COUPON' && !item.prizeName"
                  class="coupon-add_btn "
                  size="small"
                  type="primary"
                  @click="addCoupons(index, '', 'beInvited')"
                  >添加优惠券</el-button
                >
                <el-button
                  size="small"
                  style="height: 32px; margin-left: 10px"
                  class="btnClass"
                  v-if="item.virtualPrizeTypes == 'COUPON' && item.prizeName"
                  >{{ item.prizeName }}</el-button
                >
                <el-button
                  size="small"
                  style="height: 32px; margin-left: 10px"
                  type="primary"
                  @click="addCoupons(index, '', 'beInvited')"
                  v-if="item.prizeName && item.virtualPrizeTypes == 'COUPON'"
                  >重新选择</el-button
                >
              </el-form-item>
              <!-- 实物奖品 -->
              <el-form-item
                ref="beinvitedPhy"
                :prop="`inviteesUserAwards[${index}].prizeName`"
                :rules="{
                  required: item.virtualPrizeTypes === 'PHYSICALS_PRIZE',
                  message: '填写实物名称',
                  trigger: 'blur'
                }"
              >
                <el-input
                  v-if="item.virtualPrizeTypes === 'PHYSICALS_PRIZE'"
                  v-model="item.prizeName"
                  class="prize-input"
                  clearable
                  :maxlength="maxLength"
                >
                </el-input>
              </el-form-item>
              <el-button
                style="height:32px"
                @click="deleteBeInvited(index)"
                class="form-btn"
                type="danger"
                icon="el-icon-delete"
                size="small"
                >删除</el-button
              >
              <!-- inviteActivityConfig.inviteesUserAwards[index].maxPrizeNum -->
              <el-button
                style="height:32px"
                v-if="index == inviteesUserObj.inviteesUserAwards.length - 1"
                @click="addBeInvited()"
                class="m_left"
                type="primary"
                icon="el-icon-plus"
                size="small"
                >添加</el-button
              >
            </div>
          </el-form-item>
        </el-form>
        <!-- 邀请阶段奖励 -->
        <el-form ref="beStage" :model="stageRewardConfig" label-width="150px">
          <el-form-item label="邀请阶段奖励">
            <!-- 邀请阶段开启关闭按钮 -->
            <el-radio-group v-model="stageRewardConfig.open">
              <el-radio :label="true">开启</el-radio>
              <el-radio :label="false">关闭</el-radio>
            </el-radio-group>
            <!-- 开启时候 -->
            <div v-show="stageRewardConfig.open">
              <div
                class="award-option"
                v-for="(stageReward, index) in stageRewardConfig.stageRewards"
                :key="index"
              >
                <!-- 用户人数 -->
                <el-form-item
                  class="form-option"
                  :prop="`stageRewards[${index}].userNumber`"
                  :rules="[
                    {
                      required: true,
                      message: '请输入人数',
                      trigger: ['blur', 'change']
                    },
                    {
                      validator: (rules, value, callback) => {
                        validStageNum(rules, value, callback)
                      },
                      trigger: ['blur']
                    }
                  ]"
                >
                  <el-input-number
                    v-model="stageReward.userNumber"
                    controls-position="right"
                    size="small"
                    :precision="0"
                    :min="1"
                    :max="awardLength"
                  ></el-input-number>
                  <span>人</span>
                </el-form-item>
                <el-form-item
                  class="form-option"
                  :prop="`stageRewards[${index}].prize.virtualPrizeTypes`"
                  :rules="[
                    {
                      required: true,
                      message: '请选择奖品类型',
                      trigger: 'blur'
                    }
                  ]"
                >
                  <el-select
                    v-model="stageReward.prize.virtualPrizeTypes"
                    size="small"
                    @change="
                      (val) => {
                        stageRewardAction(val, index, stageReward)
                      }
                    "
                  >
                    <el-option
                      v-for="virtualPrize in virtualPrizeTypeList"
                      :key="virtualPrize.dictValue"
                      :label="virtualPrize.dictLabel"
                      :value="virtualPrize.dictValue"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
                <!-- 积分数量 -->
                <el-form-item
                  ref="stageNum"
                  class="form-option"
                  v-if="stageReward.prize.virtualPrizeTypes == 'INTEGRAL'"
                  :prop="`stageRewards[${index}].prize.num`"
                  :rules="{
                    required:
                      stageReward.prize.virtualPrizeTypes === 'INTEGRAL',
                    message: '积分数量',
                    trigger: 'blur'
                  }"
                >
                  <el-input-number
                    style="margin-left:10px"
                    size="small"
                    :precision="0"
                    class="m_left"
                    v-model="stageReward.prize.num"
                    controls-position="right"
                    :min="1"
                    :max="awardLength"
                  ></el-input-number>
                </el-form-item>
                <!-- 鲜花 -->
                <el-form-item
                  ref="stageNum"
                  class="form-option"
                  v-if="stageReward.prize.virtualPrizeTypes == 'FLOWER'"
                  :prop="`stageRewards[${index}].prize.num`"
                  :rules="{
                    required: stageReward.prize.virtualPrizeTypes === 'FLOWER',
                    message: '积分数量',
                    trigger: 'blur'
                  }"
                >
                  <el-input-number
                    style="margin-left:10px"
                    size="small"
                    :precision="0"
                    class="m_left"
                    v-model="stageReward.prize.num"
                    controls-position="right"
                    :min="1"
                    :max="awardLength"
                  ></el-input-number>
                </el-form-item>
                <!-- 优惠券 -->
                <el-form-item
                  ref="stageCop"
                  class="form-option"
                  :prop="`stageRewards[${index}].prize.couponId`"
                  :rules="{
                    required: stageReward.prize.virtualPrizeTypes === 'COUPON',
                    message: '选择优惠券',
                    trigger: 'change'
                  }"
                >
                  <el-button
                    v-if="
                      stageReward.prize.virtualPrizeTypes === 'COUPON' &&
                        !stageReward.prize.prizeName
                    "
                    class="coupon-add_btn"
                    size="small"
                    type="primary"
                    @click="addCoupons(index, '', 'stage')"
                    >添加优惠券</el-button
                  >
                  <el-button
                    size="small"
                    style="height: 32px; margin-left: 10px"
                    class="btnClass"
                    v-if="
                      stageReward.prize.virtualPrizeTypes == 'COUPON' &&
                        stageReward.prize.prizeName
                    "
                    >{{ stageReward.prize.prizeName }}</el-button
                  >
                  <el-button
                    size="small"
                    style="height: 32px; margin-left: 10px"
                    type="primary"
                    @click="addCoupons(index, '', 'stage')"
                    v-if="
                      stageReward.prize.prizeName &&
                        stageReward.prize.virtualPrizeTypes == 'COUPON'
                    "
                    >重新选择</el-button
                  >
                </el-form-item>
                <!-- 实物奖品 -->
                <el-form-item
                  ref="stagePhy"
                  class="form-option"
                  :prop="`stageRewards[${index}].prize.prizeName`"
                  :rules="{
                    required:
                      stageReward.prize.virtualPrizeTypes === 'PHYSICALS_PRIZE',
                    message: '填写实物名称',
                    trigger: 'blur'
                  }"
                >
                  <el-input
                    size="small"
                    v-if="
                      stageReward.prize.virtualPrizeTypes === 'PHYSICALS_PRIZE'
                    "
                    v-model="stageReward.prize.prizeName"
                    class="prize-input"
                    clearable
                    :maxlength="maxLength"
                  >
                  </el-input>
                </el-form-item>
                <el-button
                  style="height:32px;"
                  @click="deleteStateAward(index)"
                  class="form-btn form-option"
                  type="danger"
                  icon="el-icon-delete"
                  size="small"
                  >删除</el-button
                >
                <!-- inviteActivityConfig.inviteesUserAwards[index].maxPrizeNum -->
                <el-button
                  style="height:32px;"
                  v-if="index == stageRewardConfig.stageRewards.length - 1"
                  @click="pushStateAward()"
                  class="m_left form-option"
                  type="primary"
                  icon="el-icon-plus"
                  size="small"
                  >添加</el-button
                >
              </div>
            </div>
          </el-form-item>
        </el-form>
        <!-- 邀请人数限制 -->
        <el-form label-width="150px">
          <el-form-item label="邀请人数限制(选填)">
            <el-input-number
              size="small"
              v-model="
                inviteActivityConfig.inviteUserAwards.maxInviteUserNumberByDay
              "
              controls-position="right"
              :precision="0"
              :min="0"
              :max="awardLength"
            ></el-input-number>
            人/天
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <!-- 提交 -->
    <div class="submit-wrap">
      <el-button
        type="primary"
        class="award-remove_btn"
        size="medium"
        @click="complie"
        v-if="this.$route.query.type == 'complie'"
        >保存</el-button
      >
      <el-button
        v-else
        type="primary"
        class="award-remove_btn"
        size="medium"
        @click="onSubmit"
        >保存</el-button
      >
      <el-button @click="onCancel" class="award-remove_btn" size="medium"
        >取消</el-button
      >
    </div>
    <addCounpDialog
      :formInline="formInline"
      :total="total"
      :pages="pages"
      @backData="backData"
    ></addCounpDialog>
  </div>
</template>

<script>
import addCounpDialog from '@component/markingActive/common/addCounpDialog'
import uploadSingImg from '@common/uploadSingImg' // 上传单个图片公共组件
import { sysNormalDisable } from '@utils/dictionariesFunc'
import '@assets/css/quill.snow.css'
import { quillEditor } from 'vue-quill-editor'
import { clearTagMixins } from '@/mixins/clearTag'
import {
  addActives,
  maxNum,
  searchActive,
  changeActives
} from '@/api/activeList/index.js'

export default {
  mixins: [clearTagMixins],
  data() {
    // 验证活动规则
    var validRuleDescribe = (rules, value, callback) => {
      if (this.inviteActivityConfig.ruleDescribeOpen) {
        if (!this.inviteActivityConfig.ruleDescribe) {
          callback(new Error('请填写活动规则'))
        } else if (this.nowLength > 500) {
          callback(new Error('规则字数不能超过五百字'))
        } else {
          callback()
        }
      } else {
        callback()
      }
    }
    return {
      postId: '',
      // 富文本配置
      editorOption: {
        modules: {
          toolbar: {
            container: [
              ['bold', 'italic', 'underline', 'strike'],
              [{ header: 1 }, { header: 2 }],
              [{ list: 'ordered' }, { list: 'bullet' }],
              [{ color: [] }, { background: [] }],
              [{ align: [] }]
            ]
          },
          clipboard: {
            matchers: [[Node.ELEMENT_NODE, this.HandleCustomMatcher]]
          }
        },
        placeholder: '请输入正文'
      },
      total: 0,
      pages: {
        page: 1,
        size: 10
      },
      // 选择优惠券参数
      formInline: {
        show: false,
        // counpList: [],
        index: '',
        type: '',
        ind: ''
      },
      awardLength: 0,
      nowLength: 0,
      maxLen: 500,
      maxLength: 0,
      activityInfo: {
        name: '', //名称
        collegeId: '', //学院
        marqueeOpen: false, //跑马灯
        startTime: '', //活动开始时间
        endTime: '', //活动结束时间
        type: 'INVITE_ACTIVITY', //活动类型
        specificActivityType: 'INVITE_ACTIVITY',
        activityTime: [],
        //活动领奖配置
        receiveAwardConfig: {
          open: false,
          startTime: '', //领奖开始时间
          endTime: '' //领奖结束时间
        },
        //活动预热配置
        warmUpConfig: {
          open: false,
          startTime: '',
          endTime: '',
          cover: '',
          preheatTime: []
        }
      },
      activityInfoRules: {
        name: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { max: 20, message: '长度不能大于20个字符', trigger: 'blur' }
        ],
        activityTime: [
          {
            required: true,
            message: '活动起始时间',
            trigger: 'blur'
          }
        ]
      },
      collegesList: [], //学院列表
      activityTypeList: [], //活动类型列表
      awardModelList: [], //邀请模式
      virtualPrizeTypeList: [], //虚拟奖品下拉选项
      userBehaviorList: [], //用户行为下拉选项
      //邀请活动配置
      inviteActivityConfig: {
        poster: '', //海报
        ruleDescribeOpen: false, //规则描述开关
        ruleDescribe: '', //规则描述
        //邀请人奖励
        inviteUserAwards: {
          awardModel: 'GENERAL_REWARD_MODEL', //奖励模式
          maxInviteUserNumberByDay: undefined //邀请人数限制 为空或者为null 计数器的默认值为0 undefined才会默认为空
        }
      },
      //邀请阶段奖励
      stageRewardConfig: {
        open: false, //开启、关闭状态
        //邀请阶段奖励中遍历的数组
        stageRewards: [
          {
            prize: {
              couponId: '',
              maxPrizeNum: '',
              num: '',
              prizeName: '',
              type: '',
              virtualPrizeTypes: ''
            },
            userNumber: 1
          }
        ]
      },
      rulesInvitees: {},
      //被邀请人奖励
      inviteesUserObj: {
        inviteesUserAwards: [
          {
            couponId: '',
            maxPrizeNum: '',
            num: '',
            prizeName: '',
            type: 'VIRTUAL_PRIZE',
            virtualPrizeTypes: ''
          }
        ]
      },

      //普通邀请人奖励
      generalRewardObj: {
        generalRewardAwards: [
          {
            couponId: '',
            num: 0,
            prizeName: '',
            type: '',
            virtualPrizeTypes: ''
          }
        ]
      },

      //用户行为奖励
      behaviorRewardsObj: {
        behaviorRewards: [
          {
            prize: {
              couponId: '',
              maxPrizeNum: '',
              num: 0,
              prizeName: '',
              type: '',
              virtualPrizeTypes: ''
            },
            userBehavior: ''
          }
        ]
      },
      //邀请活动中的阶梯奖励
      ladderRewardAwards: {},
      stateObj: {
        stage: [
          [
            {
              couponId: '',
              maxPrizeNum: '',
              num: 1,
              prizeName: '',
              type: '',
              virtualPrizeTypes: ''
            }
          ]
        ]
      },

      inviteActivityConfigRules: {
        poster: [
          { required: true, message: '请上传活动海报', trigger: 'blur' }
        ],
        ruleDescribe: [
          { required: true, validator: validRuleDescribe, trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    behaviorAwardCheck() {
      let behavior = this.behaviorRewardsObj.behaviorRewards
      // 用户行为大于1条的时候必须进行校验
      if (behavior.length > 1) {
        return true
      } else {
        //  用户行为只有一条时候 如果选中了用户行为 或者 奖品选项 必须进行校验
        if (behavior[0].prize.virtualPrizeTypes || behavior[0].userBehavior) {
          return true
        } else {
          //  用户行为只有一条 并且两个都没有选中 就不进行校验
          return false
        }
      }
    }
  },
  components: {
    uploadSingImg,
    quillEditor,
    addCounpDialog
  },
  activated() {
    this.toTableScrollHeight()
  },
  created() {
    this.getNumMax()
    // 字数限制
    this.awardMaxNum()
    this.postId = this.$route.query.id
    if (
      this.$route.query.type == 'complie' ||
      this.$route.query.type == 'copy'
    ) {
      this.searchActive()
    }
  },
  async mounted() {
    const [
      collegeData,
      activityTypeData,
      awardModelData,
      virtualPrizeTypeData,
      userBehaviorData
    ] = await Promise.all([
      sysNormalDisable('sys_college', 'sys_college'),
      sysNormalDisable('marketing_activity_type', 'marketing_activity_type'),
      sysNormalDisable('marketing_award_model', 'marketing_award_model'),
      sysNormalDisable(
        'marketing_invitation_prize_type',
        'marketing_invitation_prize_type'
      ),
      sysNormalDisable('marketing_user_behavior', 'marketing_user_behavior')
    ])
    // 活动学院列表
    const defaultCollege = [{ dictLabel: '全部', dictValue: '' }]
    const defaultVirtualPrizeType = [{ dictLabel: '选择奖品', dictValue: '' }]
    const defaultUserBehaviorType = [{ dictLabel: '用户行为', dictValue: '' }]
    this.collegesList = [...defaultCollege, ...collegeData]
    this.activityTypeList = activityTypeData
    this.awardModelList = awardModelData
    this.virtualPrizeTypeList = [
      ...defaultVirtualPrizeType,
      ...virtualPrizeTypeData
    ]
    this.userBehaviorList = [...defaultUserBehaviorType, ...userBehaviorData]
  },
  methods: {
    // 活动规则 点击关闭 清除校验
    clearFileds(val) {
      if (!val) {
        this.$refs['inviteActivityConfig'].clearValidate('ruleDescribe')
      }
    },
    signOut() {
      this.$router.go(-1)
    },
    dueDateToAwardTime(startTime, endTime) {
      this.$set(this.activityInfo.receiveAwardConfig, 'receiveTime', [
        startTime,
        endTime
      ])
    },
    dueDateToFireTime(startTime, endTime) {
      this.$set(this.activityInfo.warmUpConfig, 'preheatTime', [
        startTime,
        endTime
      ])
    },
    dueDateToActiveTime(startTime, endTime) {
      this.$set(this.activityInfo, 'activityTime', [startTime, endTime])
    },
    HandleCustomMatcher(node, Delta) {
      if (this.clearStyle) {
        let ops = []
        Delta.ops.forEach((op) => {
          if (op.insert && typeof op.insert === 'string') {
            ops.push({
              insert: op.insert
            })
          }
        })
        Delta.ops = ops
        return Delta
      } else {
        return Delta
      }
    },
    onEditorBlur(event) {},
    onEditorChange(event) {
      let value = event.quill.getText()
      this.textContent = value.slice(0, -1)
      if (this.inviteActivityConfig.ruleDescribe === '') {
        this.nowLength = 0
      } else {
        this.nowLength = value.length - 1
      }
      this.overTextLottery = this.nowLength > this.maxLen ? true : false
      if (this.overTextLottery) {
        this.$message.warning(`文章内容不超过${this.maxLen}字`)
      }
    },
    complie() {
      let _this = this
      let activityInfo
      let inviteActivityConfig
      // 被邀请活动
      let beInvitees
      // 阶段邀请奖励
      let beStage
      //用户行为奖励
      let behavior
      // 普通邀请奖励
      let general
      // 阶梯奖励
      let ladder
      if (
        this.inviteActivityConfig.inviteUserAwards.awardModel ==
        'GENERAL_REWARD_MODEL'
      ) {
        this.$refs['generalRef'].validate((valid) => {
          general = valid
          if (!valid) {
            this.$message.warning('请检查必填项')
          }
        })
      }
      if (
        this.inviteActivityConfig.inviteUserAwards.awardModel ==
        'LADDER_REWARD_MODEL'
      ) {
        this.$refs['ladderForm'].validate((valid) => {
          // ladder = valid
          ladder = valid
          if (!valid) {
            this.$message.warning('请检查必填项')
          }
        })
      }
      this.$refs['activityInfo'].validate((valid) => {
        activityInfo = valid
        if (!valid) {
          this.$message.warning('请检查必填项')
        }
      })
      this.$refs['inviteActivityConfig'].validate((valid) => {
        inviteActivityConfig = valid
        if (!valid) {
          this.$message.warning('请检查必填项')
        }
      })
      this.$refs['beInvitees'].validate((valid) => {
        beInvitees = valid
        if (!valid) {
          this.$message.warning('请检查必填项')
        }
      })
      this.$refs['behaviorRef'].validate((valid) => {
        behavior = valid
        if (!valid) {
          this.$message.warning('请检查必填项')
        }
      })
      // 阶段邀请表单校验 只有开启的时候才会校验 当阶段邀请关闭的时候直接赋值为true 通过校验
      if (this.stageRewardConfig.open) {
        this.$refs['beStage'].validate((valid) => {
          beStage = valid
          if (!valid) {
            this.$message.warning('请检查必填项')
          }
        })
      } else {
        beStage = true
        this.stageRewardConfig.stageRewards = null
      }
      if (
        activityInfo &&
        inviteActivityConfig &&
        beInvitees &&
        beStage &&
        behavior &&
        general
      ) {
        // 被邀请人奖励如果只有一条 并且没有选中奖品类型 就给赋值为空
        if (
          this.inviteesUserObj.inviteesUserAwards.length == 1 &&
          !this.inviteesUserObj.inviteesUserAwards[0].virtualPrizeTypes
        ) {
          this.inviteActivityConfig.inviteesUserAwards = []
        } else {
          this.inviteActivityConfig.inviteesUserAwards = this.inviteesUserObj.inviteesUserAwards
        }
        this.inviteActivityConfig.inviteUserAwards.stageRewardConfig = this.stageRewardConfig
        // 如果用户行为奖励只有一条 并且没有选中用户行为和 用户奖励 赋值为空
        if (
          this.behaviorRewardsObj.behaviorRewards.length === 1 &&
          !this.behaviorRewardsObj.behaviorRewards[0].prize.virtualPrizeTypes &&
          !this.behaviorRewardsObj.behaviorRewards[0].userBehavior
        ) {
          this.inviteActivityConfig.inviteUserAwards.behaviorRewards = []
        } else {
          this.inviteActivityConfig.inviteUserAwards.behaviorRewards = this.behaviorRewardsObj.behaviorRewards
        }
        this.inviteActivityConfig.inviteUserAwards.generalRewardAwards = this.generalRewardObj.generalRewardAwards
        if (
          _this.generalRewardObj.generalRewardAwards.length == 1 &&
          _this.generalRewardObj.generalRewardAwards[0].virtualPrizeTypes == ''
        ) {
          _this.inviteActivityConfig.inviteUserAwards.generalRewardAwards = null
        }
        let params = {}
        params.activityInfo = this.activityInfo
        params.inviteActivityConfig = this.inviteActivityConfig
        changeActives(
          this.postId,
          params,
          (res) => {
            this.clearTag()
          },
          (err) => {
            this.$message({
              message: err.message,
              type: 'warning'
            })
            // this.clearTag()
          }
        )
      }
      // 当走的阶梯奖励的时候
      if (
        activityInfo &&
        inviteActivityConfig &&
        beInvitees &&
        beStage &&
        behavior &&
        ladder
      ) {
        for (let key in this.stateObj.stage) {
          this.ladderRewardAwards[key] = this.stateObj.stage[key]
        }
        // 被邀请人奖励如果只有一条 并且没有选中奖品类型 就给赋值为空
        if (
          this.inviteesUserObj.inviteesUserAwards.length == 1 &&
          !this.inviteesUserObj.inviteesUserAwards[0].virtualPrizeTypes
        ) {
          this.inviteActivityConfig.inviteesUserAwards = []
        } else {
          this.inviteActivityConfig.inviteesUserAwards = this.inviteesUserObj.inviteesUserAwards
        }
        this.inviteActivityConfig.inviteUserAwards.stageRewardConfig = this.stageRewardConfig
        // 如果用户行为奖励只有一条 并且没有选中用户行为和 用户奖励 赋值为空
        if (
          this.behaviorRewardsObj.behaviorRewards.length === 1 &&
          !this.behaviorRewardsObj.behaviorRewards[0].prize.virtualPrizeTypes &&
          !this.behaviorRewardsObj.behaviorRewards[0].userBehavior
        ) {
          this.inviteActivityConfig.inviteUserAwards.behaviorRewards = []
        } else {
          this.inviteActivityConfig.inviteUserAwards.behaviorRewards = this.behaviorRewardsObj.behaviorRewards
        }
        this.inviteActivityConfig.inviteUserAwards.ladderRewardAwards = this.ladderRewardAwards
        if (
          this.stateObj.stage.length == 1 &&
          this.stateObj.stage[0].length == 1 &&
          !this.stateObj.stage[0][0].virtualPrizeTypes
        ) {
          this.inviteActivityConfig.inviteUserAwards.ladderRewardAwards = null
        }
        let params = {}
        params.activityInfo = this.activityInfo
        params.inviteActivityConfig = this.inviteActivityConfig
        addActives(
          params,
          (res) => {
            this.clearTag()
          },
          (err) => {
            this.$message({
              message: err.message,
              type: 'warning'
            })
            // this.clearTag()
          }
        )
      }
    },
    // 编辑一键复制回显
    searchActive() {
      let _this = this
      let obj = {}
      searchActive(
        this.postId,
        obj,
        (res) => {
          this.activityInfo = res.activityInfo
          let {
            poster,
            ruleDescribeOpen,
            ruleDescribe
          } = res.inviteActivityConfig
          this.inviteActivityConfig.poster = poster
          this.inviteActivityConfig.ruleDescribeOpen = ruleDescribeOpen
          this.inviteActivityConfig.ruleDescribe = ruleDescribe
          // 被邀请人奖励
          // 判断被邀请人奖励的数组不为空的时候在赋值
          if (res.inviteActivityConfig.inviteesUserAwards.length > 0) {
            this.inviteesUserObj.inviteesUserAwards =
              res.inviteActivityConfig.inviteesUserAwards
          }
          let {
            awardModel,
            maxInviteUserNumberByDay,
            behaviorRewards,
            generalRewardAwards,
            stageRewardConfig,
            ladderRewardAwards
          } = res.inviteActivityConfig.inviteUserAwards
          this.inviteActivityConfig.inviteUserAwards.awardModel = awardModel
          if (!maxInviteUserNumberByDay) {
            this.inviteActivityConfig.inviteUserAwards.maxInviteUserNumberByDay = undefined
          } else {
            this.inviteActivityConfig.inviteUserAwards.maxInviteUserNumberByDay = maxInviteUserNumberByDay
          }

          if (awardModel === 'GENERAL_REWARD_MODEL') {
            // 因为阶段奖励关闭状态下 返回的stageRewards 为null 所以需要判断一下是否为值
            if (stageRewardConfig.stageRewards) {
              this.stageRewardConfig = stageRewardConfig
            }
            // 判断用户行为奖励的数组不为空的时候 才赋值 否则使用data中的数据
            if (behaviorRewards.length > 0) {
              this.behaviorRewardsObj.behaviorRewards = behaviorRewards
              this.behaviorRewardsObj.behaviorRewards.map((item) => {
                if (item.prize.virtualPrizeTypes == 'INTEGRAL') {
                  _this.$set(item.prize, 'num', item.prize.num)
                }
              })
            }

            // 因为后台数据返回一个空的数组 所以直接用length判断 用！判断失效
            if (generalRewardAwards.length > 0) {
              this.generalRewardObj.generalRewardAwards = generalRewardAwards
            }
          }
          if (awardModel === 'LADDER_REWARD_MODEL') {
            if (stageRewardConfig.stageRewards) {
              this.stageRewardConfig = stageRewardConfig
            }
            // 判断用户行为奖励的数组不为空的时候 才赋值 否则使用data中的数据
            if (behaviorRewards.length > 0) {
              this.behaviorRewardsObj.behaviorRewards = behaviorRewards
            }
            // 阶梯奖励返回的是一个对象 需要一个数组包含数组的数据结构 所以需要进行处理
            if (ladderRewardAwards) {
              let array = new Array()

              for (let key in ladderRewardAwards) {
                array.push(ladderRewardAwards[key])
              }
              this.$set(this.stateObj, 'stage', array)
            }
          }
          if (res.activityInfo.startTime && res.activityInfo.endTime)
            this.dueDateToActiveTime(
              res.activityInfo.startTime,
              res.activityInfo.endTime
            )

          if (
            res.activityInfo.warmUpConfig.startTime &&
            res.activityInfo.warmUpConfig.endTime
          )
            this.dueDateToFireTime(
              res.activityInfo.warmUpConfig.startTime,
              res.activityInfo.warmUpConfig.endTime
            )

          if (
            res.activityInfo.receiveAwardConfig.startTime &&
            res.activityInfo.receiveAwardConfig.endTime
          )
            this.dueDateToAwardTime(
              res.activityInfo.receiveAwardConfig.startTime,
              res.activityInfo.receiveAwardConfig.endTime
            )
          // }
        },
        (err) => {}
      )
    },
    // 阶梯选填 默认空的时候可以不校验
    validLadder(rules, value, callback) {
      if (
        this.stateObj.stage.length == 1 &&
        !this.stateObj.stage[0][0].virtualPrizeTypes
      ) {
        callback()
        return false
      }
      let threeLadder = this.stateObj.stage.map((item) => {
        let passFalse = item.map((one) => {
          if (one.virtualPrizeTypes) {
            return one.virtualPrizeTypes
          } else {
            return false
          }
        })
        if (passFalse.includes(false)) {
          callback(new Error('请选择奖品类型'))
          return false
        }
        let wannaData = passFalse.filter((two) => {
          return two !== false
        })
        if (this.insRepat(wannaData)) {
          callback(new Error('奖品类型重复'))
          return false
        }
      })
      if (!threeLadder.includes(false)) {
        callback()
      }
    },
    //  阶梯中奖品类型切换
    checkLabelState(val, ind, index) {
      if (val == 'PHYSICALS_PRIZE') {
        this.stateObj.stage[index][ind].type = 'PHYSICALS_PRIZE'
        this.stateObj.stage[index][ind].prizeName = ''
        this.stateObj.stage[index][ind].couponId = ''
        this.$refs['ladderNum'][ind].clearValidate()
        this.$refs['ladderCop'][ind].clearValidate()
      } else {
        this.stateObj.stage[index][ind].type = 'VIRTUAL_PRIZE'
        this.stateObj.stage[index][ind].prizeName = ''
        this.stateObj.stage[index][ind].couponId = ''
        this.$refs['ladderPhy'][ind].clearValidate()
        if (val == 'INVITE_ACTIVITY') {
          this.stateObj.stage[index][ind].prizeName = '积分'
          this.stateObj.stage[index][ind].couponId = ''
          this.$refs['ladderCop'][ind].clearValidate()
        }
        if (val == 'COUPON') {
          this.stateObj.stage[index][ind].prizeName = ''
          this.stateObj.stage[index][ind].num = ''
          this.$refs['ladderNum'][ind].clearValidate()
        }
      }
    },
    // 删除阶梯
    deleteStage(index) {
      if (this.stateObj.stage.length == 1) {
        this.$message({
          message: '至少一条',
          type: 'warning'
        })
        return false
      }
      this.stateObj.stage.splice(index, 1)
    },
    getNumMax() {
      let obj = {
        configKey: 'marketing_activity_prize_name_limit'
      }
      maxNum(
        obj,
        (res) => {
          this.maxLength = res
        },
        (err) => {}
      )
    },
    addStage() {
      if (this.stateObj.stage.length == 3) {
        this.$message({
          message: '阶梯奖励不可以超过三个',
          type: 'warning'
        })
        return false
      }
      this.stateObj.stage.push([
        {
          couponId: '',
          maxPrizeNum: '',
          num: '',
          prizeName: '',
          type: '',
          virtualPrizeTypes: ''
        }
      ])
    },
    addInner(ind, index) {
      if (this.stateObj.stage[index].length == 3) {
        this.$message({
          message: '最多可以添加三条',
          type: 'warning'
        })
        return false
      }
      this.stateObj.stage[index].push({
        couponId: '',
        maxPrizeNum: '',
        num: '',
        prizeName: '',
        type: '',
        virtualPrizeTypes: ''
      })
    },
    deleteInner(ind, index) {
      if (this.stateObj.stage[index].length == 1) {
        this.$message({
          message: '至少保留一条',
          type: 'warning'
        })
        return false
      }

      this.$delete(this.stateObj.stage[index], ind)
      console.log(this.stateObj.stage, 'this.stateObj.stagethis.stateObj.stage')
    },
    // 普通邀请 选填 当一条为空时候是不要校验的
    validGeneral(rules, value, callback) {
      let generl = this.generalRewardObj.generalRewardAwards
      if (generl.length == 1 && !generl[0].virtualPrizeTypes) {
        callback()
      } else {
        let hasFalse = generl.map((item) => {
          if (item.virtualPrizeTypes) return item.virtualPrizeTypes
          return false
        })
        if (hasFalse.includes(false)) {
          callback(new Error('请选择奖品类型'))
          return false
        }
        let delFalse = hasFalse.filter((one) => {
          return one !== false
        })
        if (this.insRepat(delFalse)) {
          callback(new Error('有重复奖品类型'))
        } else {
          callback()
        }
      }
    },
    // 用户行为的添加 删除方法
    deleteUserMove(index) {
      if (this.behaviorRewardsObj.behaviorRewards.length == 1) {
        this.$message({
          message: '最少要保留一条',
          type: 'warning'
        })
        return false
      }
      this.behaviorRewardsObj.behaviorRewards.splice(index, 1)
    },
    addUserMove() {
      if (this.behaviorRewardsObj.behaviorRewards.length == 9) {
        this.$message({
          message: '用户行为奖励最多可添加九条',
          type: 'warning'
        })
        return false
      }
      this.behaviorRewardsObj.behaviorRewards.push({
        prize: {
          couponId: '',
          maxPrizeNum: '',
          num: '',
          prizeName: '',
          type: '',
          virtualPrizeTypes: ''
        },
        disabled: true,
        userBehavior: ''
      })
    },
    // 用户行为奖励奖品切换方法
    checkedUserBehavor(val, index) {
      let behavior = this.behaviorRewardsObj.behaviorRewards
      if (val == 'PHYSICALS_PRIZE') {
        behavior[index].prize.type = 'PHYSICALS_PRIZE'
        behavior[index].prize.prizeName = ''
        this.$refs['behaviorCounp'][index].clearValidate()
        this.$refs['behaviorNum'][index].clearValidate()
      } else {
        this.$refs['behaviorPhy'][index].clearValidate()
        if (val == 'INTEGRAL') {
          behavior[index].prize.type = 'VIRTUAL_PRIZE'
          behavior[index].prize.prizeName = '积分'
          this.$refs['behaviorCounp'][index].clearValidate()
        }
        if (val == 'COUPON') {
          behavior[index].prize.type = 'VIRTUAL_PRIZE'
          behavior[index].prize.prizeName = ''
          behavior[index].prize.couponId = ''
          this.$ref['behaviorNum'][index].clearValidate()
        }
        if (val == 'FLOWER') {
          behavior[index].prize.type = 'VIRTUAL_PRIZE'
          behavior[index].prize.prizeName = ''
          behavior[index].prize.couponId = ''
          this.$ref['behaviorNum'][index].clearValidate()
        }
      }
    },
    // 用户行为校验重复用户选择和奖品选项
    validBehavior(rules, value, callback) {
      let behaviors = this.behaviorRewardsObj.behaviorRewards.map((item) => {
        if (item.prize.virtualPrizeTypes && item.userBehavior) {
          return item.userBehavior + item.prize.virtualPrizeTypes
        }
        return false
      })
      let copy = behaviors.filter((item) => {
        return item !== false
      })
      if (this.insRepat(copy)) {
        callback(new Error('用户和奖品选项重复'))
      } else {
        callback()
      }
    },
    validStageOpen(rules, values, callback) {
      if (!this.stageRewardConfig.open) {
        callback()
      }
    },
    validStageNum(rules, values, callback) {
      let stageNum = this.stageRewardConfig.stageRewards.map((item) => {
        return item.userNumber
      })
      if (this.insRepat(stageNum)) {
        callback(new Error('有重复选择人数'))
      } else {
        callback()
      }
    },
    deleteStateAward(index) {
      if (this.stageRewardConfig.stageRewards.length == 1) {
        this.$message({
          message: '至少需要一条',
          type: 'warning'
        })
        return false
      }
      this.stageRewardConfig.stageRewards.splice(index, 1)
    },
    // 阶段邀请添加方法
    pushStateAward() {
      if (this.stageRewardConfig.stageRewards.length == 20) {
        this.$message({
          message: '最多三条',
          type: 'warning'
        })
        return false
      }
      this.stageRewardConfig.stageRewards.push({
        prize: {
          couponId: '',
          maxPrizeNum: '',
          num: '',
          prizeName: '',
          type: '',
          virtualPrizeTypes: ''
        },
        userNumber: ''
      })
    },
    // 阶段奖励切换奖项
    stageRewardAction(val, index) {
      if (val == 'PHYSICALS_PRIZE') {
        this.stageRewardConfig.stageRewards[index].prize.type =
          'PHYSICALS_PRIZE'
        this.stageRewardConfig.stageRewards[index].prize.prizeName = ''
        this.stageRewardConfig.stageRewards[index].prize.couponId = ''
        this.stageRewardConfig.stageRewards[index].prize.num = ''
        this.$refs['stageNum'][index].clearValidate()
        this.$refs['stageCop'][index].clearValidate()
      } else {
        this.stageRewardConfig.stageRewards[index].prize.type = 'VIRTUAL_PRIZE'
        if (val == 'INTEGRAL') {
          this.stageRewardConfig.stageRewards[index].prize.prizeName = '积分'
          this.stageRewardConfig.stageRewards[index].prize.couponId = ''
          this.$refs['stageCop'][index].clearValidate()
        }
        if (val == 'COUPON') {
          this.stageRewardConfig.stageRewards[index].prize.prizeName = ''
          this.stageRewardConfig.stageRewards[index].prize.num = ''
          this.$refs['stageNum'][index].clearValidate()
        }
        this.$refs['stagePhy'][index].clearValidate()
      }
    },
    // 判断数组中是否有相同元素
    insRepat(arr) {
      let obj = {}
      for (let key in arr) {
        if (obj[arr[key]]) return true
        obj[arr[key]] = true
      }
      return false
    },
    // 验证被邀请人奖励中是否又重复奖项
    validBeInvite(rulse, value, callback) {
      let inviteesUserAwards = this.inviteesUserObj.inviteesUserAwards
      let prizeTypes = inviteesUserAwards.map((item) => {
        return item.virtualPrizeTypes
      })
      if (this.insRepat(prizeTypes)) {
        callback(new Error('选择奖项不能重复'))
      } else {
        callback()
      }
    },
    // 被邀请人奖励的添加 删除方法
    deleteBeInvited(index) {
      if (this.inviteesUserObj.inviteesUserAwards.length == 1) {
        this.$message({
          message: '至少保留一条',
          type: 'warning'
        })
        return false
      }
      this.inviteesUserObj.inviteesUserAwards.splice(index, 1)
    },
    addBeInvited() {
      if (this.inviteesUserObj.inviteesUserAwards.length == '3') {
        this.$message({
          message: '最多可以添加三条',
          type: 'warning'
        })
        return false
      }
      this.inviteesUserObj.inviteesUserAwards.push({
        couponId: '',
        num: '',
        prizeName: '',
        type: 'VIRTUAL_PRIZE',
        virtualPrizeTypes: ''
      })
    },
    // 添加优惠券 添加优惠券弹窗返回的数据
    backData(backData, index, ind, type) {
      if (type == 'general') {
        this.generalRewardObj.generalRewardAwards[index].couponId = backData.id
        this.generalRewardObj.generalRewardAwards[index].prizeName =
          backData.couponName
      }
      if (type == 'beInvited') {
        this.inviteesUserObj.inviteesUserAwards[index].couponId = backData.id
        this.inviteesUserObj.inviteesUserAwards[index].prizeName =
          backData.couponName
      }
      if (type == 'stage') {
        this.stageRewardConfig.stageRewards[index].prize.couponId = backData.id
        this.stageRewardConfig.stageRewards[index].prize.prizeName =
          backData.couponName
      }
      if (type == 'behavior') {
        this.behaviorRewardsObj.behaviorRewards[index].prize.couponId =
          backData.id
        this.behaviorRewardsObj.behaviorRewards[index].prize.prizeName =
          backData.couponName
      }
      if (type == 'ladder') {
        console.log('111')
        this.stateObj.stage[index][ind].couponId = backData.id
        this.stateObj.stage[index][ind].prizeName = backData.couponName
      }
      if (type == 'draw') {
        this.lotteryActivityConfig.awards[index].prize.couponId = backData.id
        this.lotteryActivityConfig.awards[index].prize.prizeName =
          backData.couponName
      }
    },
    // 添加优惠券
    addCoupons(index, ind, type) {
      this.formInline.index = index
      this.formInline.type = type
      this.formInline.ind = ind
      this.formInline.show = true
    },
    awardMaxNum() {
      let obj = {
        configKey: 'marketing_activity_prize_number_limit'
      }
      maxNum(
        obj,
        (res) => {
          this.awardLength = res
        },
        (err) => {}
      )
    },
    // 更改奖品类型；
    checkedAward(val, index, item) {
      if (val === 'PHYSICALS_PRIZE') {
        this.inviteesUserObj.inviteesUserAwards[index].virtualPrizeTypes =
          'PHYSICALS_PRIZE'
        this.inviteesUserObj.inviteesUserAwards[index].type = 'PHYSICALS_PRIZE'
        this.inviteesUserObj.inviteesUserAwards[index].prizeName = ''
        this.inviteesUserObj.inviteesUserAwards[index].couponId = ''
        this.$refs['beinvitedNum'][index].clearValidate()
        this.$refs['beinvitedCoup'][index].clearValidate()
      } else {
        this.$refs['beinvitedPhy'][index].clearValidate()
        this.inviteesUserObj.inviteesUserAwards[index].type = 'VIRTUAL_PRIZE'
        this.inviteesUserObj.inviteesUserAwards[index].prizeName = ''
        if (val == 'INTEGRAL') {
          this.inviteesUserObj.inviteesUserAwards[index].couponId = ''
          this.inviteesUserObj.inviteesUserAwards[index].prizeName = '积分'
          this.$refs['beinvitedCoup'][index].clearValidate()
        }
        if (val == 'COUPON') {
          this.inviteesUserObj.inviteesUserAwards[index].prizeName = ''
          this.$refs['beinvitedNum'][index].clearValidate()
        }
      }
    },
    changeActivityTime(val) {
      this.activityInfo.startTime = val[0]
      this.activityInfo.endTime = val[1]
    },
    changePreheatTime(val) {
      this.activityInfo.warmUpConfig.startTime = val[0]
      this.activityInfo.warmUpConfig.endTime = val[1]
    },
    changeReceiveTime(val) {
      this.activityInfo.receiveAwardConfig.startTime = val[0]
      this.activityInfo.receiveAwardConfig.endTime = val[1]
    },
    changeInviteUserAward(val, index, item) {
      this.$set(
        this.generalRewardObj.generalRewardAwards[index],
        'virtualPrizeTypes',
        val
      )
      if (val === 'PHYSICALS_PRIZE') {
        this.generalRewardObj.generalRewardAwards[index].type =
          'PHYSICALS_PRIZE'
        this.generalRewardObj.generalRewardAwards[index].couponId = ''
        this.generalRewardObj.generalRewardAwards[index].prizeName = ''
        this.generalRewardObj.generalRewardAwards[index].num = ''
        this.$refs['generalNum'][index].clearValidate()
        this.$refs['generalCop'][index].clearValidate()
      } else {
        this.generalRewardObj.generalRewardAwards[index].type = 'VIRTUAL_PRIZE'
        this.generalRewardObj.generalRewardAwards[index].couponId = ''
        this.generalRewardObj.generalRewardAwards[index].prizeName = ''
        this.generalRewardObj.generalRewardAwards[index].num = ''
        this.$refs['generalPhy'][index].clearValidate()
        if (val === 'INTEGRAL') {
          this.generalRewardObj.generalRewardAwards[index].prizeName = '积分'
          this.generalRewardObj.generalRewardAwards[index].couponId = ''
          this.$refs['generalCop'][index].clearValidate()
        }
        if (val === 'COUPON') {
          this.generalRewardObj.generalRewardAwards[index].prizeName = ''
          this.generalRewardObj.generalRewardAwards[index].num = ''
          this.$refs['generalNum'][index].clearValidate()
        }
      }
    },
    //添加邀请人奖励
    addInviteUserAwards() {
      if (this.generalRewardObj.generalRewardAwards.length == 3) {
        this.$message({
          message: '不能添加超过三个',
          type: 'warning'
        })
        return false
      }
      this.generalRewardObj.generalRewardAwards.push({
        couponId: '',
        num: '',
        prizeName: '',
        type: '',
        virtualPrizeTypes: ''
      })
    },
    //删除邀请人奖项
    deleteInviteUserAwards(index) {
      if (this.generalRewardObj.generalRewardAwards.length == 1) {
        this.$message({
          message: '至少保留一个',
          type: 'warning'
        })
        return false
      }
      this.generalRewardObj.generalRewardAwards.splice(index, 1)
      this.generalRewardObj.generalRewardAwards.splice(index, 1)
    },
    getImgUrl(url) {
      this.activityInfo.warmUpConfig.cover = url
    },
    getActivePoster(url) {
      this.$nextTick(() => {
        this.inviteActivityConfig.poster = url
      })
    },
    onSubmit() {
      let _this = this
      let activityInfo
      let inviteActivityConfig
      // 被邀请活动
      let beInvitees
      // 阶段邀请奖励
      let beStage
      //用户行为奖励
      let behavior
      // 普通邀请奖励
      let general
      // 阶梯奖励
      let ladder
      if (
        this.inviteActivityConfig.inviteUserAwards.awardModel ==
        'GENERAL_REWARD_MODEL'
      ) {
        this.$refs['generalRef'].validate((valid) => {
          general = valid
          if (!valid) {
            this.$message.warning('请检查必填项')
          }
        })
      }
      if (
        this.inviteActivityConfig.inviteUserAwards.awardModel ==
        'LADDER_REWARD_MODEL'
      ) {
        this.$refs['ladderForm'].validate((valid) => {
          // ladder = valid
          ladder = valid
          if (!valid) {
            this.$message.warning('请检查必填项')
          }
        })
      }
      this.$refs['activityInfo'].validate((valid) => {
        activityInfo = valid
        if (!valid) {
          this.$message.warning('请检查必填项')
        }
      })
      this.$refs['inviteActivityConfig'].validate((valid) => {
        inviteActivityConfig = valid
        if (!valid) {
          this.$message.warning('请检查必填项')
        }
      })
      this.$refs['beInvitees'].validate((valid) => {
        beInvitees = valid
        if (!valid) {
          this.$message.warning('请检查必填项')
        }
      })
      this.$refs['behaviorRef'].validate((valid) => {
        behavior = valid
        if (!valid) {
          this.$message.warning('请检查必填项')
        }
      })
      // 阶段邀请表单校验 只有开启的时候才会校验 当阶段邀请关闭的时候直接赋值为true 通过校验
      if (this.stageRewardConfig.open) {
        this.$refs['beStage'].validate((valid) => {
          beStage = valid
          if (!valid) {
            this.$message.warning('请检查必填项')
          }
        })
      } else {
        beStage = true
        this.stageRewardConfig.stageRewards = null
      }
      if (
        activityInfo &&
        inviteActivityConfig &&
        beInvitees &&
        beStage &&
        behavior &&
        general
      ) {
        // 被邀请人奖励如果只有一条 并且没有选中奖品类型 就给赋值为空
        if (
          this.inviteesUserObj.inviteesUserAwards.length == 1 &&
          !this.inviteesUserObj.inviteesUserAwards[0].virtualPrizeTypes
        ) {
          this.inviteActivityConfig.inviteesUserAwards = []
        } else {
          this.inviteActivityConfig.inviteesUserAwards = this.inviteesUserObj.inviteesUserAwards
        }

        this.inviteActivityConfig.inviteUserAwards.stageRewardConfig = this.stageRewardConfig
        // 如果用户行为奖励只有一条 并且没有选中用户行为和 用户奖励 赋值为空
        if (
          this.behaviorRewardsObj.behaviorRewards.length === 1 &&
          !this.behaviorRewardsObj.behaviorRewards[0].prize.virtualPrizeTypes &&
          !this.behaviorRewardsObj.behaviorRewards[0].userBehavior
        ) {
          this.inviteActivityConfig.inviteUserAwards.behaviorRewards = []
        } else {
          this.inviteActivityConfig.inviteUserAwards.behaviorRewards = this.behaviorRewardsObj.behaviorRewards
        }

        this.inviteActivityConfig.inviteUserAwards.generalRewardAwards = this.generalRewardObj.generalRewardAwards
        if (
          _this.generalRewardObj.generalRewardAwards.length == 1 &&
          _this.generalRewardObj.generalRewardAwards[0].virtualPrizeTypes == ''
        ) {
          _this.inviteActivityConfig.inviteUserAwards.generalRewardAwards = null
        }
        let params = {}
        params.activityInfo = this.activityInfo
        params.inviteActivityConfig = this.inviteActivityConfig
        addActives(
          params,
          (res) => {
            this.clearTag()
          },
          (err) => {
            this.$message({
              message: err.message,
              type: 'warning'
            })
          }
        )
      }

      if (
        activityInfo &&
        inviteActivityConfig &&
        beInvitees &&
        beStage &&
        behavior &&
        ladder
      ) {
        for (let key in this.stateObj.stage) {
          this.ladderRewardAwards[key] = this.stateObj.stage[key]
        }
        // 被邀请人奖励如果只有一条 并且没有选中奖品类型 就给赋值为空
        if (
          this.inviteesUserObj.inviteesUserAwards.length == 1 &&
          !this.inviteesUserObj.inviteesUserAwards[0].virtualPrizeTypes
        ) {
          this.inviteActivityConfig.inviteesUserAwards = []
        } else {
          this.inviteActivityConfig.inviteesUserAwards = this.inviteesUserObj.inviteesUserAwards
        }
        this.inviteActivityConfig.inviteUserAwards.stageRewardConfig = this.stageRewardConfig
        // 如果用户行为奖励只有一条 并且没有选中用户行为和 用户奖励 赋值为空
        if (
          this.behaviorRewardsObj.behaviorRewards.length === 1 &&
          !this.behaviorRewardsObj.behaviorRewards[0].prize.virtualPrizeTypes &&
          !this.behaviorRewardsObj.behaviorRewards[0].userBehavior
        ) {
          this.inviteActivityConfig.inviteUserAwards.behaviorRewards = []
        } else {
          this.inviteActivityConfig.inviteUserAwards.behaviorRewards = this.behaviorRewardsObj.behaviorRewards
        }
        this.inviteActivityConfig.inviteUserAwards.ladderRewardAwards = this.ladderRewardAwards
        if (
          this.stateObj.stage.length == 1 &&
          this.stateObj.stage[0].length == 1 &&
          !this.stateObj.stage[0][0].virtualPrizeTypes
        ) {
          this.inviteActivityConfig.inviteUserAwards.ladderRewardAwards = null
        }
        let params = {}
        params.activityInfo = this.activityInfo
        params.inviteActivityConfig = this.inviteActivityConfig
        addActives(
          params,
          (res) => {
            this.clearTag()
          },
          (err) => {
            this.$message({
              message: err.message,
              type: 'warning'
            })
          }
        )
      }
    },
    onCancel() {
      this.clearTag()
    }
  }
}
</script>
<style lang="less" scoped>
.form-option {
  margin-top: 20px;
}
.ladder {
  margin-top: 80px;
}
.near-top {
  margin-top: -2px !important;
}
.form-near-top {
  margin-top: -5px !important;
}
.behavior-item {
  margin-top: -8px !important;
}
.btn-height {
  height: 32px !important;
}
.behavior {
  .behaviorInner {
    div:nth-of-type(n + 2) {
      margin-top: 15px;
      &:extend(.row_center);
    }
  }
}
.row_center {
  display: flex;
  justify-content: flex-start;
  align-items: center;
}
.btnClass {
  height: 32px;
  margin-left: 10px;
  background: #1dc8a4;
  color: white;
  box-shadow: 0px 0px 1px rgba(52, 52, 52, 0.5);
  border-radius: 5px;
}
:deep(.el-input__inner) {
  height: 32px;
}
.form-btn {
  margin-left: 20px;
}
.limit {
  height: 30px;
  line-height: 30px;
  text-align: right;
  margin: 20px 0 10px;
  padding-right: 10px;
  span {
    color: #f00;
  }
}
.activity-input {
  width: 500px;
}
.award-option {
  display: flex;
  align-items: center;
  .prize-input {
    width: 194px;
    margin-left: 10px;
    height: 32px;
  }
  .prize-option {
    margin-left: 10px;
  }
  .number-option {
    margin-left: 20px;
  }
  .coupon-add_btn {
    height: 32px !important;
    margin-left: 10px;
  }
  .award-add_btn {
    height: 32px;
    margin-left: 10px;
    color: #169bd5;
    border-color: #169bd5;
    background: white;
  }
  .award-remove_btn {
    height: 32px;
    margin-left: 10px;
    color: #e41952;
    background: white;
  }
}
.submit-wrap {
  margin: 20px 20px 30px 550px;
}
</style>
